package cn.mln521.test;

import cn.mln521.annotation.demo1.UserService;
import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SpringDemo1 {

    /**
     * @Component
     * @Service
     *  等 注解
     */
    @Test
    public void demo1() {
        ApplicationContext context = new ClassPathXmlApplicationContext("application.xml");
        UserService userService = (UserService) context.getBean("userService");
        String s = userService.sayHello("张三");
        System.out.println(s);
    }

    /**
     * 注解  属性注入 用 @Value 一般不适用
     */
    @Test
    public void demo2() {
        ApplicationContext context = new ClassPathXmlApplicationContext("application.xml");
        UserService userService = (UserService) context.getBean("userService");
        userService.eat();
    }
    /**
     * 注解
     * @Auto
     */
    @Test
    public void demo3() {
        ApplicationContext context = new ClassPathXmlApplicationContext("application.xml");
        UserService userService = (UserService) context.getBean("userService");
        userService.save();
    }

}
